﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SCM.Common;
using SCM.Servie.IBusiness;

namespace SCM.Manage.Controllers
{
    [Authorize]
    public class SysErrorLogController : BaseController
    {
        #region 系统异常
        public IActionResult SysIndex()
        {
            return View();
        }

        [HttpPost]
        public IActionResult SysErrorSearch(string ip, string userName, string msg, string source, int index = 1)
        {
            var service = GetService<ILogService>();
            var errorPage = service.Query(ip, userName, msg, source, new Common.PageInfo() { PageIndex = index, PageSize = 10 });
            return GetOk(new { totalCount = errorPage.Page.DataCount, items = errorPage.Data });
        }

        public IActionResult EditSysView(string id)
        {
            var model = GetService<ILogService>().GetErrorLog(id);
            return View(model);
        }
        #endregion

        #region 业务异常
        public IActionResult BusinessIndex()
        {
            return View();
        }

        [HttpPost]
        public IActionResult BusinessSearch(string ip, string userName, string content, int index = 1)
        {
            var service = GetService<ILogService>();
            var businessPage = service.Query(ip, userName, content, new Common.PageInfo() { PageIndex = index, PageSize = 10 });
            return GetOk(new { totalCount = businessPage.Page.DataCount, items = businessPage.Data });
        }

        public IActionResult EditBusinessView(string id)
        {
            var model = GetService<ILogService>().GetBusinessLog(id);
            return View(model);
        }
        #endregion
    }
}
